package common;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.net.Socket;



public class ClientSocket implements ClientInterface,Serializable {
	
	private Socket socket;
	private BufferedReader streamin;
	private BufferedWriter streamout;
	private int token;
	String string;
	
	public ClientSocket(Socket socket){
		this.socket=socket;
		try{
			streamin=new BufferedReader(new InputStreamReader(socket.getInputStream()));
			streamout=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	
	public BufferedWriter getOut() {
		return streamout;
	}

	
	public void setOut(BufferedWriter streamout) {
		this.streamout = streamout;
	}


	@Override
	public void cambioTurno(String username) throws IOException{
		display("@cambioTurno,"+username);
	}


	public void setToken(int token) {
		this.token = token;
	}


	public int getToken() {
		return token;
	}

	
	public void setIn(BufferedReader in) {
		this.streamin = in;
	}


	public BufferedReader getIn() {
		return streamin;
	}


	@Override
	public void gameOver(String message) throws IOException {
		display(message);
	}


	@Override
	public void display(String s) throws IOException {
		streamout.write(s);
		streamout.newLine();
		streamout.flush();		
	}

}
